package com.example.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Map.Entry;

import com.example.bean.dto.CustomerCompanyDTO;
import com.example.bean.vo.*;
import com.example.service.BlockchainApplicationService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.formula.functions.Column;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


/***
 * poi操作Execl
 * 导入poi相关jar
 *
 */
public class ExportExcel {

	public final static Map<String,String> projectlevel = new HashMap() {{  
		put("1","国家级");
		put("2","省级");
		put("3","其他");

	}};


	public final static Map<String,String> returnWorkStatus = new HashMap() {{  
		put("1","未复工");
		put("2","复工");

	}};

	public final static Map<String,String> firsttype = new HashMap() {{   
		put("1","硬件组件");
		put("2","软件组件");
		put("3","平台");
		put("4","服务");
		put("5","应用");
		put("6","产业服务");
		put("7","基础设施");
		put("8","其他");

	}};
	public final static Map<String,String> sectype = new HashMap() {{   
		put("11","可信存储和计算");
		put("12","矿机芯片");
		put("21","共识算法");
		put("22","智能合约");
		put("23","密钥管理");
		put("24","跨链/并发");
		put("25","安全");
		put("26","交易所");
		put("27","钱包");
		put("31","公有链");
		put("32","联盟链");
		put("33","闭源联盟链");
		put("41","平台即服务");
		put("42","区块链云服务BaaS");
		put("51","金融服务");
		put("52","存证/溯源");
		put("53","数字身份");
		put("54","供应链");
		put("55","民生");
		put("56","政务");
		put("57","支付");
		put("61","行业组织");
		put("62","市场服务");
		put("63","产品服务");
		put("71","基础设施");
		put("81","其他");

	}};
	DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
	public void exportdata(String str,String modelExcel,String newExcel,List<BlockchainCompanyInfo> dataList, BlockchainApplicationService service) {
		ExportExcel excel=new ExportExcel();
		try {

			System.out.println(excel.copyFile(str,modelExcel,newExcel));
			String url=newExcel+str;
			FileInputStream fs;
			fs = new FileInputStream(url);
			Workbook wb = null;

			if (url.toLowerCase().endsWith(".xlx")) {
				wb = new HSSFWorkbook(fs);
			} else if (url.toLowerCase().endsWith(".xlsx")) {
				wb = new XSSFWorkbook(fs);
			}

			Sheet sheetAt0=wb.getSheetAt(0);  //企业信息
			Row row0=sheetAt0.getRow(0);
			int hang0=0;
			if("".equals(row0)||row0==null){
				hang0=0;
			}else{
				hang0=sheetAt0.getLastRowNum();	
				hang0=hang0+1;	
			}

			FileOutputStream out=new FileOutputStream(url);  //向d://test.xls中写数据  
			
			for(BlockchainCompanyInfo info:dataList) {
				int colindex=0;
				Row row=sheetAt0.createRow((short)(hang0)); //在现有行号后追加数据  
				row.createCell(colindex++).setCellValue(hang0-1); //设置第一个（从0开始）单元格的数据  
				row.createCell(colindex++).setCellValue(info.getAdvanceUnit());//推荐单位
				row.createCell(colindex++).setCellValue(info.getAdvanceName());//推荐人姓名
				row.createCell(colindex++).setCellValue(info.getAdvancePhone());//联系方式
				row.createCell(colindex++).setCellValue(info.getName());
				row.createCell(colindex++).setCellValue(info.getGeneralCreditCode());
				row.createCell(colindex++).setCellValue(info.getEnterpriseType());//企业性质
				row.createCell(colindex++).setCellValue(info.getCompanyType());//企业类型
				String time=info.getFoundationDate().format(df);
				row.createCell(colindex++).setCellValue(time);//成立日期

				row.createCell(colindex++).setCellValue(info.getBusinessTerm());//营业期限
				time=info.getIssueDate().format(df);
				row.createCell(colindex++).setCellValue(time);//发照日期
				row.createCell(colindex++).setCellValue(info.getRegistrationAuthority());
				row.createCell(colindex++).setCellValue(info.getBusinessStatus());
				row.createCell(colindex++).setCellValue(info.getLegalPerson());
				row.createCell(colindex++).setCellValue(info.getLegalPersonCode());
				row.createCell(colindex++).setCellValue(info.getCompanyPhone());
				row.createCell(colindex++).setCellValue(info.getRegisteredCapital().toString());
				row.createCell(colindex++).setCellValue(info.getProvince()+"-"+info.getCity());
				row.createCell(colindex++).setCellValue(info.getAddress());
				row.createCell(colindex++).setCellValue(info.getIndustry());//所属行业
				row.createCell(colindex++).setCellValue(returnWorkStatus.get(info.getReturnWorkStatus()));
				row.createCell(colindex++).setCellValue(info.getLicenseImgUrl());
				row.createCell(colindex++).setCellValue(info.getIdCardFrontUrl());
				row.createCell(colindex++).setCellValue(info.getIdCardBackUrl());
				row.createCell(colindex++).setCellValue(info.getPark());
				if(info.getIsHighTech())row.createCell(colindex++).setCellValue("是");
				else row.createCell(colindex++).setCellValue("否");
				row.createCell(colindex++).setCellValue(info.getStaffCount());
				row.createCell(colindex++).setCellValue(info.getTotalRevenue().toString());
				row.createCell(colindex++).setCellValue(info.getWebsite());
				row.createCell(colindex++).setCellValue(info.getMainPerson());
				row.createCell(colindex++).setCellValue(info.getMainPersonDuty());
				row.createCell(colindex++).setCellValue(info.getMainPersonMobile());
				row.createCell(colindex++).setCellValue(info.getMainPersonEmail());
				row.createCell(colindex++).setCellValue(info.getContactPerson());
				row.createCell(colindex++).setCellValue(info.getContactPersonDuty());
				row.createCell(colindex++).setCellValue(info.getContactPersonMobile());
				row.createCell(colindex++).setCellValue(info.getContactPersonEmail());
				row.createCell(colindex++).setCellValue(info.getContactPersonWechat());
				row.createCell(colindex++).setCellValue(info.getContactPersonAddress());
				row.createCell(colindex++).setCellValue(info.getBusinessScope());
				row.createCell(colindex++).setCellValue("");
				row.createCell(colindex++).setCellValue("");
				row.createCell(colindex++).setCellValue("");
				row.createCell(colindex++).setCellValue("");
				row.createCell(colindex++).setCellValue("");//客户企业
				row.createCell(colindex++).setCellValue(info.getType());
				time=info.getBuildTeamDate().format(df);
				row.createCell(colindex++).setCellValue(time);//区块链团队日期
				row.createCell(colindex++).setCellValue(info.getBlockchainStaffCount());
				row.createCell(colindex++).setCellValue(info.getBlockchainRevenue().toString());
				row.createCell(colindex++).setCellValue(info.getBlockchainteamvarious());
				row.createCell(colindex++).setCellValue(info.getBlockchainInnovate());
				row.createCell(colindex++).setCellValue("");
				hang0++;
				BlockchainCompanyInfoVO vos= service.getblockinfos(info);
				getsheet1(vos,wb.getSheetAt(1));//产品信息
				getsheet3(vos,wb.getSheetAt(2));//投融资情况
				getsheet4(vos,wb.getSheetAt(3));//企业创始人
				getsheet5(vos,wb.getSheetAt(4));//技术带头人
				getsheet6(vos,wb.getSheetAt(5));//专家
				System.out.println(row.getCell(1));

			}
			out.flush();  
			wb.write(out);    
			out.close();    
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}
	/*
	 * 区块链产品信息
	 */
	public void getsheet1(BlockchainCompanyInfoVO vos,Sheet sheet) {
		Row row=sheet.getRow(0);
		int hang=0;
		if("".equals(row)||row==null){
			hang=0;
		}else{
			hang=sheet.getLastRowNum();	
			hang=hang+1;	
		}
		for(ProductInfoVO custom:vos.getProductInfos()) {

			Row productrow=sheet.createRow((short)(hang)); //在现有行号后追加数据 
			int colindex=0;
			productrow.createCell(colindex++).setCellValue(vos.getGeneralCreditCode());
			productrow.createCell(colindex++).setCellValue(custom.getName());
			productrow.createCell(colindex++).setCellValue(custom.getUrl());
			productrow.createCell(colindex++).setCellValue(firsttype.get(custom.getFirsttype()));
			productrow.createCell(colindex++).setCellValue(sectype.get(custom.getSectype()));
			productrow.createCell(colindex++).setCellValue(custom.getTypeadd());
			productrow.createCell(colindex++).setCellValue(custom.getAdvance());
			productrow.createCell(colindex++).setCellValue(custom.getCreateAblity());
			int newindex=colindex;
			colindex=colindex+6;
			productrow.createCell(colindex++).setCellValue(custom.getProductscale().getCountscale());
			productrow.createCell(colindex++).setCellValue(custom.getProductscale().getUsercscale());
			productrow.createCell(colindex++).setCellValue(custom.getProductscale().getInfoscale());
			productrow.createCell(colindex++).setCellValue(custom.getSecurity());
			if(custom.getOpensource().equals("1"))productrow.createCell(colindex++).setCellValue("是");
			else productrow.createCell(colindex++).setCellValue("否");
			productrow.createCell(colindex++).setCellValue(projectlevel.get(custom.getProjectlevel()));
			int usecaseindex=newindex;
			for(int i=0;i<custom.getUseCase().size();i++) {
				UseCaseVO usecase=custom.getUseCase().get(i);
				usecaseindex=newindex;
				if(i==0) {
					productrow.createCell(usecaseindex++).setCellValue(usecase.getName());
					productrow.createCell(usecaseindex++).setCellValue(usecase.getCompany());
					String time=usecase.getSubmitDate().format(df);
					productrow.createCell(usecaseindex++).setCellValue(time);
					productrow.createCell(usecaseindex++).setCellValue(usecase.getAppliLocation());
					productrow.createCell(usecaseindex++).setCellValue(usecase.getProblem());
					productrow.createCell(usecaseindex++).setCellValue(usecase.getValue());

				}
				else {
					Row productrow1=sheet.createRow((short)(hang)); //在现有行号后追加数据 
					
					productrow1.createCell(usecaseindex++).setCellValue(usecase.getName());
					productrow1.createCell(usecaseindex++).setCellValue(usecase.getCompany());
					String time=usecase.getSubmitDate().format(df);
					productrow1.createCell(usecaseindex++).setCellValue(time);
					productrow1.createCell(usecaseindex++).setCellValue(usecase.getAppliLocation());
					productrow1.createCell(usecaseindex++).setCellValue(usecase.getProblem());
					productrow1.createCell(usecaseindex++).setCellValue(usecase.getValue());
					
				}
				hang++;

			}

		}

	}
	/*
	 * 客户企业信息
	 */
	public void getsheet2(BlockchainCompanyInfoVO vos,Sheet sheet) {
		Row row=sheet.getRow(0);
		int hang=0;
		if("".equals(row)||row==null){
			hang=0;
		}else{
			hang=sheet.getLastRowNum();	
			hang=hang+1;	
		}
		for(CustomerCompanyDTO custom:vos.getCustomerCompanyInfos()) {
			Row productrow=sheet.createRow((short)(hang)); //在现有行号后追加数据 
			productrow.createCell(0).setCellValue(vos.getGeneralCreditCode());
			productrow.createCell(1).setCellValue(custom.getName());

			productrow.createCell(2).setCellValue(custom.getEnterpriseType());
			hang++;

		}
	}
	/*
	 * 投融资情况
	 */
	public void getsheet3(BlockchainCompanyInfoVO vos,Sheet sheet) {
		Row row=sheet.getRow(0);
		int hang=0;
		if("".equals(row)||row==null){
			hang=0;
		}else{
			hang=sheet.getLastRowNum();	
			hang=hang+1;	
		}
		for(InvestmentFinacingVO custom:vos.getInvestmetnfinacing()) {
			Row productrow=sheet.createRow((short)(hang)); //在现有行号后追加数据 
			productrow.createCell(0).setCellValue(vos.getGeneralCreditCode());
			productrow.createCell(1).setCellValue(custom.getLunci());
			String time=custom.getTime().format(df);
			productrow.createCell(2).setCellValue(time);
			productrow.createCell(3).setCellValue(custom.getCount().toString());
			productrow.createCell(4).setCellValue(custom.getSource());
			hang++;

		}
	}
	/*
	 * 企业创始人
	 */
	public void getsheet4(BlockchainCompanyInfoVO vos,Sheet sheet) {
		Row row=sheet.getRow(0);
		int hang=0;
		if("".equals(row)||row==null){
			hang=0;
		}else{
			hang=sheet.getLastRowNum();	
			hang=hang+1;	
		}
		for(FounderProfileVO custom:vos.getCreateleader()) {
			if(custom.getType()==0) {
				Row productrow=sheet.createRow((short)(hang)); //在现有行号后追加数据 
				productrow.createCell(0).setCellValue(vos.getGeneralCreditCode());
				productrow.createCell(1).setCellValue(custom.getName());
			
				productrow.createCell(2).setCellValue(custom.getAge());
				productrow.createCell(3).setCellValue(custom.getEducation());
				productrow.createCell(4).setCellValue(custom.getSchool());
				productrow.createCell(5).setCellValue(custom.getWorkExper());
				productrow.createCell(6).setCellValue(custom.getMajorResult());
				productrow.createCell(7).setCellValue(custom.getDuty());
				productrow.createCell(8).setCellValue(custom.getReward());
				hang++;
			}

		}
	}
	/*
	 * 技术带头人
	 */
	public void getsheet5(BlockchainCompanyInfoVO vos,Sheet sheet) {
		Row row=sheet.getRow(0);
		int hang=0;
		if("".equals(row)||row==null){
			hang=0;
		}else{
			hang=sheet.getLastRowNum();	
			hang=hang+1;	
		}
		for(FounderProfileVO custom:vos.getTechnologyleader()) {
			if(custom.getType()==1) {
				Row productrow=sheet.createRow((short)(hang)); //在现有行号后追加数据 
				productrow.createCell(0).setCellValue(vos.getGeneralCreditCode());
				productrow.createCell(1).setCellValue(custom.getName());
			
				productrow.createCell(2).setCellValue(custom.getAge());
				productrow.createCell(3).setCellValue(custom.getEducation());
				productrow.createCell(4).setCellValue(custom.getSchool());
				productrow.createCell(5).setCellValue(custom.getWorkExper());
				productrow.createCell(6).setCellValue(custom.getMajorResult());
				productrow.createCell(7).setCellValue(custom.getDuty());
				productrow.createCell(8).setCellValue(custom.getReward());
				hang++;
			}

		}
	}
	/*
	 * 专家顾问
	 */
	public void getsheet6(BlockchainCompanyInfoVO vos,Sheet sheet) {
		Row row=sheet.getRow(0);
		int hang=0;
		if("".equals(row)||row==null){
			hang=0;
		}else{
			hang=sheet.getLastRowNum();	
			hang=hang+1;	
		}
		for(ExpertVO custom:vos.getExperts()) {

			Row productrow=sheet.createRow((short)(hang)); //在现有行号后追加数据 
			int colindex=0;
			productrow.createCell(colindex++).setCellValue(vos.getGeneralCreditCode());
			productrow.createCell(colindex++).setCellValue(custom.getName());
			productrow.createCell(colindex++).setCellValue(custom.getAge());
			productrow.createCell(colindex++).setCellValue(custom.getProfessionalTitle());
			productrow.createCell(colindex++).setCellValue(custom.getUnit());
			productrow.createCell(colindex++).setCellValue(custom.getDuty());
			productrow.createCell(colindex++).setCellValue(custom.getWorkResult());
			
			productrow.createCell(colindex++).setCellValue(custom.getSocialDuty());
			productrow.createCell(colindex++).setCellValue(custom.getReward());
			int newindex=colindex;
			int usecaseindex=newindex;
			/*for(PatentVO usecase:custom.getPatent()) {
				usecaseindex=newindex;
				if(productrow.getCell(0)!=null&&productrow.getCell(0).toString().length()>0) {
					productrow.createCell(usecaseindex++).setCellValue(usecase.getName());
					productrow.createCell(usecaseindex++).setCellValue(usecase.getCompany());
					String time=usecase.getSubmitDate().format(df);
					productrow.createCell(usecaseindex++).setCellValue(time);
					productrow.createCell(usecaseindex++).setCellValue(usecase.getAppliLocation());
					productrow.createCell(usecaseindex++).setCellValue(usecase.getProblem());
					productrow.createCell(usecaseindex++).setCellValue(usecase.getValue());

				}
				else {
					Row productrow1=sheet.createRow((short)(hang)); //在现有行号后追加数据 
					productrow1.createCell(usecaseindex++).setCellValue(usecase.getName());
					productrow1.createCell(usecaseindex++).setCellValue(usecase.getCompany());
					String time=usecase.getSubmitDate().format(df);
					productrow1.createCell(usecaseindex++).setCellValue(time);
					productrow1.createCell(usecaseindex++).setCellValue(usecase.getAppliLocation());
					productrow1.createCell(usecaseindex++).setCellValue(usecase.getProblem());
					productrow1.createCell(usecaseindex++).setCellValue(usecase.getValue());
				}
				hang++;

			}*/
			hang++;

		}
	}




	protected Workbook getWorkbook(String url) throws IOException {
		File file = new File(url);
		String fileName = file.getName();
		FileInputStream fileInputStream = new FileInputStream(file);
		Workbook workbook = null;
		if (fileName.toLowerCase().endsWith(".xlx")) {
			workbook = new HSSFWorkbook(fileInputStream);
		} else if (fileName.toLowerCase().endsWith(".xlsx")) {
			workbook = new XSSFWorkbook(fileInputStream);
		}
		return workbook;
	}
	/**
	 * 创建表格样式
	 * @param wb 工作薄对象
	 * @return 样式列表
	 */
	private Map<String, CellStyle> createStyles(Workbook wb) {
		Map<String, CellStyle> styles = new HashMap<String, CellStyle>();

		CellStyle style = wb.createCellStyle();
		style.setAlignment(CellStyle.ALIGN_CENTER);
		style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		Font titleFont = wb.createFont();
		titleFont.setFontName("Arial");
		titleFont.setFontHeightInPoints((short) 16);
		titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
		style.setFont(titleFont);
		styles.put("title", style);

		style = wb.createCellStyle();
		style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		Font dataFont = wb.createFont();
		dataFont.setFontName("Arial");
		dataFont.setFontHeightInPoints((short) 10);
		style.setFont(dataFont);
		styles.put("data", style);

		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
		style.setAlignment(CellStyle.ALIGN_LEFT);
		styles.put("data1", style);

		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
		style.setAlignment(CellStyle.ALIGN_CENTER);
		styles.put("data2", style);

		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
		style.setAlignment(CellStyle.ALIGN_RIGHT);
		styles.put("data3", style);

		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
		//		style.setWrapText(true);
		style.setAlignment(CellStyle.ALIGN_CENTER);
		style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
		style.setFillPattern(CellStyle.SOLID_FOREGROUND);
		Font headerFont = wb.createFont();
		headerFont.setFontName("Arial");
		headerFont.setFontHeightInPoints((short) 10);
		headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
		headerFont.setColor(IndexedColors.WHITE.getIndex());
		style.setFont(headerFont);
		styles.put("header", style);

		return styles;
	}





	//复制excel文件
	private  boolean copyFile(String str,String sourcePath,String destPath) throws IOException
	{
		boolean f = false;
		String destFilePath = destPath+str;
		String sourceFilePath = sourcePath+str;
		File newDir = new File(destFilePath.substring(0,destFilePath.lastIndexOf('/')));
		File sourceFile = new File(sourceFilePath.trim());
		if(!sourceFile.exists())
		{

			return f;
		}
		File destFile = new File(destFilePath.trim());
		if (!newDir.exists()){
			newDir.mkdirs();
		}
		if(!sourceFile.isDirectory())
		{
			InputStream in=new FileInputStream(sourceFile);
			FileOutputStream out=new FileOutputStream(destFile);
			byte[] buffer=new byte[1024];
			int ins;
			while((ins=in.read(buffer))!=-1){
				out.write(buffer,0,ins);
			}
			in.close();
			out.flush();
			out.close();
			f = true;
		}
		return f;

	}
	//	public static void main(String[] args) throws IOException {
	//		String str="model.xlsx";
	//		String modelExcel="E:/cjd/";
	//		String newExcel="E:/cjd/"+DateUtil.formatDate(new Date(),"yyyyMMddHHmmss")+"/";
	//		File file=new File(newExcel);
	//		file.mkdirs();
	//		ExportExcel excel=new ExportExcel();
	//		excel.copyFile(str,modelExcel,newExcel);
	//		String url=newExcel+str;
	//		FileInputStream fs;
	//		try {
	//			fs = new FileInputStream(url);
	//			Workbook wb = null;
	//
	//			if (url.toLowerCase().endsWith(".xlx")) {
	//				wb = new HSSFWorkbook(fs);
	//			} else if (url.toLowerCase().endsWith(".xlsx")) {
	//				wb = new XSSFWorkbook(fs);
	//			}
	//
	//			Sheet sheet=wb.getSheetAt(0);  //获取到工作表，因为一个excel可能有多个工作表  
	//			Row row=sheet.getRow(0);
	//			int hang=0;
	//			if("".equals(row)||row==null){
	//				hang=0;
	//			}else{
	//				hang=sheet.getLastRowNum();	
	//				hang=hang+1;	
	//			}
	//			//分别得到最后一行的行号，和一条记录的最后一个单元格         
	//			FileOutputStream out=new FileOutputStream(url);  //向d://test.xls中写数据  
	//			row=sheet.createRow((short)(hang)); //在现有行号后追加数据  
	//			row.createCell(0).setCellValue(hang-1); //设置第一个（从0开始）单元格的数据  
	//			row.createCell(1).setCellValue("安庆"); //设置第二个（从0开始）单元格的数据  
	//			sheet=wb.getSheetAt(1);  //获取到工作表，因为一个excel可能有多个工作表  
	//			row=sheet.getRow(0);
	//			hang=0;
	//			if("".equals(row)||row==null){
	//				hang=0;
	//			}else{
	//				hang=sheet.getLastRowNum();	
	//				hang=hang+1;	
	//			}
	//			row=sheet.createRow((short)(hang)); //在现有行号后追加数据  
	//			row.createCell(0).setCellValue(hang); //设置第一个（从0开始）单元格的数据  
	//			row.createCell(1).setCellValue("安庆"); //设置第二个（从0开始）单元格的数据  
	//			sheet=wb.getSheetAt(2);  //获取到工作表，因为一个excel可能有多个工作表  
	//			row=sheet.getRow(0);
	//			hang=0;
	//			if("".equals(row)||row==null){
	//				hang=0;
	//			}else{
	//				hang=sheet.getLastRowNum();	
	//				hang=hang+1;	
	//			}
	//			row=sheet.createRow((short)(hang)); //在现有行号后追加数据  
	//			row.createCell(0).setCellValue(hang); //设置第一个（从0开始）单元格的数据  
	//			row.createCell(1).setCellValue("安庆"); //设置第二个（从0开始）单元格的数据  
	//
	//			out.flush();  
	//			wb.write(out);    
	//			out.close();    
	//
	//		} catch (IOException e) {
	//			// TODO Auto-generated catch block
	//			e.printStackTrace();
	//		}  
	//	}








}
